package org.luxor.common.netty.protocol;


import io.netty.util.internal.StringUtil;
import org.luxor.common.netty.constant.NettyReasonCode;
import org.luxor.commons.core.web.IRestStatus;

/**
 * Netty Result VariableHeader
 *
 * @author Mr.yan @date 2024/1/31
 */
public class NettyReasonCodeVariableHeader {
    private final int reasonCode;
    private final String reasonMsg;

    public NettyReasonCodeVariableHeader(int reasonCode, String reasonMsg) {
        this.reasonCode = reasonCode;
        this.reasonMsg = reasonMsg;
    }

    public int reasonCode() {
        return this.reasonCode;
    }

    public String reasonMsg() {
        return this.reasonMsg;
    }

    public static NettyReasonCodeVariableHeader from(int errorCode, String errorMessage) {
        return new NettyReasonCodeVariableHeader(errorCode, errorMessage);
    }

    public static NettyReasonCodeVariableHeader from(IRestStatus reasonStatus) {
        return NettyReasonCodeVariableHeader.from(reasonStatus.code(), reasonStatus.message());
    }

    public static NettyReasonCodeVariableHeader from() {
        return NettyReasonCodeVariableHeader.from(NettyReasonCode.SUCCESS.code(), NettyReasonCode.SUCCESS.message());
    }

    @Override
    public String toString() {
        return StringUtil.simpleClassName(this) +
                '[' +
                "reasonCode=" + reasonCode +
                ", reasonMsg=" + reasonMsg +
                ']';
    }
}
